import {reqGetCode,reqUserRegister} from '@/api'
import {getUserTempId,} from '@/utils/userAbout'

const state = {
  // 初始化的时候就获取用户的临时标识存储到这里
  userTempId:getUserTempId(),
  code:'',
}


const mutations = {
  REVEIVE_CODE(state,code){
    state.code = code
  }
}


const actions = {
  async getCode({commit},phone){
    const result = await reqGetCode(phone)
    if(result.code === 200){
      commit('REVEIVE_CODE',result.data)
      return result.data
    }else{
      return Promise.reject(new Error('failed'))
    }
  },


  async userRegister({commit},userInfo){
    const result = await reqUserRegister(userInfo)
    if(result.code === 200){
      return 'ok'
    }else{
      return Promise.reject(new Error('failed'))
    }
  },

}
const getters = {}

export default {
  state,
  mutations,
  actions,
  getters
}